# http://www.imbi.uni-freiburg.de/parallel/docs/Reisensburg2009_TutParallelComputing_Knaus_Porzelius.pdf
library(snowfall)

sfInit(parallel=TRUE, cpus=8)

sfLibrary(igraph)

s32c <- read.graph(file = "eat-seed32-core-graphml.xml", format = "graphml")
mc <- readRDS("maximal-cliques.rds")

#sfExport("s32c", "mc")
sfExportAll()

nc <- length(mc)

get.words <- function(i)
{
	nodes <- V(s32c)[mc[[i]]]$name
	words <- c()

	for (j in c(1:length(nodes)))
	{
		node <- nodes[[j]]

		for (z in strsplit(node, "\\."))
		{
			words <- append(words, z)
		}
	}

	words <- tolower(unique(words))
}

cliques <- sfLapply(1:nc, get.words)
saveRDS(cliques, "clique-words.rds")

print(length(cliques))

sfStop()
